#include "StdAfx.h"
#include "MentorCircuitPart.h"
#include "MentorCircuitPartDisObj.h"


MentorCircuitPart::MentorCircuitPart(void)
{
	m_iMirrorType = 2;
	m_isSubPart = false;
	m_visualFlag = 0x00;
	m_pPartTypeDesignator = NULL;
}

MentorCircuitPart::MentorCircuitPart(const MentorCircuitPart *pEntityObj)
	: CCircuitPart( pEntityObj )
{
	m_iMirrorType = pEntityObj->GetMirrorType();
	m_isSubPart = pEntityObj->IsSubPart();
	m_visualFlag = pEntityObj->GetVisualFlag();
//	m_pPartTypeDesignator = pEntityObj->GetPartTypeDesignator();
	CPartDesignator* pTempDes=pEntityObj->GetPartTypeDesignator();
	m_pPartTypeDesignator = NULL;
	if (pTempDes)
	{
		m_pPartTypeDesignator = pTempDes->Clone();
	}
}

MentorCircuitPart::MentorCircuitPart(CICircuit *pParentEnt)
	: CCircuitPart( pParentEnt )
{
	m_iMirrorType = 2;
	m_isSubPart = false;
	m_visualFlag = 0x00;
	m_pPartTypeDesignator = NULL;
}

MentorCircuitPart::~MentorCircuitPart(void)
{
	Clear();
}

void MentorCircuitPart::Serialize(CArchive & ar)
{	
	if(ar.IsStoring())
	{
		ar << m_iMirrorType;
		ar << m_isSubPart;
		ar << m_visualFlag;
		m_pPartTypeDesignator->Serialize(ar);
	}
	else
	{	
		if( CObj::m_lFileVersion > 40 )
		{
			ar >> m_iMirrorType;
			ar >> m_isSubPart;
			ar >> m_visualFlag;
			m_pPartTypeDesignator = new CPartDesignator();
			m_pPartTypeDesignator->Serialize(ar);
		}

	}

	CCircuitPart::Serialize(ar);
}

CObj *MentorCircuitPart::Clone() const
{
	return new MentorCircuitPart(this);
}


void MentorCircuitPart::Transform(const CMatrix transf)
{

}

bool MentorCircuitPart::GetBox(double & dblLeft, double & dblBottom, double & dblRight, double & dblTop) const
{
	return CCircuitPart::GetBox(dblLeft, dblBottom, dblRight, dblTop);
}

void MentorCircuitPart::Clear()
{
	if(m_pPartTypeDesignator)
		delete m_pPartTypeDesignator;
}

void MentorCircuitPart::CopyDisplayObj(long lSourceLayerId, long lDestLayerId)
{
	CEntityObj::CopyDisplayObj(lSourceLayerId, lDestLayerId);

	list<CCircuitUnit *> lstSons = GetNormalUnitList();

	list<CCircuitUnit *>::iterator it_son;
	for (it_son=lstSons.begin(); it_son!=lstSons.end(); it_son++)
	{
		(*it_son)->CopyDisplayObj(lSourceLayerId, lDestLayerId);
	}
}

void MentorCircuitPart::DeleteDisplayObj(long lLayerId)
{
	CEntityObj::DeleteDisplayObj(lLayerId);

	list<CCircuitUnit *> lstSons = GetNormalUnitList();

	list<CCircuitUnit *>::iterator it_son;
	for (it_son=lstSons.begin(); it_son!=lstSons.end(); it_son++)
	{
		(*it_son)->DeleteDisplayObj(lLayerId);
	}
}

CDisplayObj *MentorCircuitPart::CreateDisplayObj(long lLayerId)
{
	MentorCircuitPartDisObj *pPartDis = new MentorCircuitPartDisObj(this);
	pPartDis->SetLayerId(lLayerId);

	list<CCircuitUnit *> lstSons = GetNormalUnitList();

	list<CCircuitUnit *>::iterator it_son;
	for (it_son=lstSons.begin(); it_son!=lstSons.end(); it_son++)
	{
		(*it_son)->CreateDisplayObj(lLayerId);
	}

	return pPartDis;
}


void MentorCircuitPart::CalcBox()
{
	CCircuitPart::CalcBox();
}

eCircuitUnitEntType MentorCircuitPart::GetUnitType() const
{
	return MENTOR_CIRCUIT_PART;
}


int MentorCircuitPart::GetMirrorType() const
{
	return m_iMirrorType;
}

void MentorCircuitPart::SetMirrorType(int type )
{
	m_iMirrorType = type;
}


bool MentorCircuitPart::IsSubPart() const
{
	return m_isSubPart;
}

void MentorCircuitPart::SetIsSubPart(bool val)
{
	m_isSubPart = val;
}


int MentorCircuitPart::GetVisualFlag() const
{
	return m_visualFlag;
}

void MentorCircuitPart::SetVisualFlag(int val)
{
	m_visualFlag = val;
}

void MentorCircuitPart::SetPartTypeDesignator(CPartDesignator *pDesginator)
{
	m_pPartTypeDesignator = pDesginator;
}

CPartDesignator *MentorCircuitPart::GetPartTypeDesignator() const
{
	return m_pPartTypeDesignator;
}